﻿using System;
using System.Collections.Generic;

namespace WordCloudHelper
{
    // Token: 0x02000004 RID: 4
    internal class OccupancyMap : IntegralImage
    {
        
        public OccupancyMap(int width, int height) : base(width, height)
        {
            this.Rand = new Random();
        }

       
        public bool TryFindUnoccupiedPosition(int sizeX, int sizeY, out int oPosX, out int oPosY)
        {
            oPosX = -1;
            oPosY = -1;
            int num = this.Rand.Next(1, base.Width);
            int num2 = this.Rand.Next(1, base.Height);
            int num5;
            int num4;
            int num3 = num4 = (num5 = 0);
            int num6 = -1;
            int val = base.Width - sizeX;
            int val2 = base.Height - sizeY;
            int num7 = Math.Max(val, val2);
            int num8 = num7 * num7;
            for (int i = 0; i < num8; i++)
            {
                int num9 = num4 + num;
                int num10 = num3 + num2;
                if (num10 > 0 && num10 < base.Height - sizeY && num9 > 0 && num9 < base.Width - sizeX && base.GetArea(num9, num10, sizeX, sizeY) == 0UL)
                {
                    oPosX = num9;
                    oPosY = num10;
                    return true;
                }
                if (num4 == num3 || (num4 < 0 && num4 == -num3) || (num4 > 0 && num4 == 1 - num3))
                {
                    num7 = num5;
                    num5 = -num6;
                    num6 = num7;
                }
                num4 += num5;
                num3 += num6;
            }
            return false;
        }

      
        private List<int> XPoses { get; set; }

       
        private List<int> YPoses { get; set; }

       
        private Random Rand { get; set; }
    }
}
